
rm(list=ls(all=TRUE))

library(lfe)
library(car)
library(stargazer)
library(data.table)
library(plyr)
library(rgdal)
library(cshapes)
library(xtable)


setwd("~/Dropbox/UK_Employment/replication")


# Functions
'%!in%' <- function(x,y)!('%in%'(x,y))



##### FIGURE 1

load("data/regulation_countries.rda")

table(stateshape@data$color)

setEPS()
postscript("output/paper/fig1.eps")
plot(stateshape, col=stateshape@data$color)
dev.off()





##### FIGURE 2

load("data/main.rda")


# sum
earnings.sum <- tapply(data$earnings.all.infl, data$year, sum)/1000000
earnings.work.infl.sum <- tapply(data$earnings.work.infl, data$year, sum)/1000000
earnings.press.infl.sum <- tapply(data$earnings.press.infl, data$year, sum)/1000000
earnings.speech.infl.sum <- tapply(data$earnings.speech.infl, data$year, sum)/1000000


# share
earnings.share <- tapply(data$earnings.all.infl>0, data$year, sum)/tapply(data$earnings.all.infl>=0, data$year, sum)
earnings.work.infl.share <- tapply(data$earnings.work.infl>0, data$year, sum)/tapply(data$earnings.work.infl>=0, data$year, sum)
earnings.press.infl.share <- tapply(data$earnings.press.infl>0, data$year, sum)/tapply(data$earnings.press.infl>=0, data$year, sum)
earnings.speech.infl.share <- tapply(data$earnings.speech.infl>0, data$year, sum)/tapply(data$earnings.speech.infl>=0, data$year, sum)


# mean earnings of those who had a job
earnings.mean.nonull <- tapply(data$earnings.all.infl[data$earnings.all.infl>0], data$year[data$earnings.all.infl>0], mean)
earnings.work.infl.mean.nonull <- tapply(data$earnings.work.infl[data$earnings.work.infl>0], data$year[data$earnings.work.infl>0], mean)
earnings.press.infl.mean.nonull <- tapply(data$earnings.press.infl[data$earnings.press.infl>0], data$year[data$earnings.press.infl>0], mean)
earnings.speech.infl.mean.nonull <- tapply(data$earnings.speech.infl[data$earnings.speech.infl>0], data$year[data$earnings.speech.infl>0], mean)



# Panel (a)
setEPS()
postscript("output/paper/fig2a.eps")

par(mar = c(2,3,1,1), mgp=c(2,0.5,0))
plot(unique(data$year), earnings.sum, type="n", ylim=c(0, ceiling(max(earnings.sum))), lwd=4, xlab="", ylab="Total Earnings in Millions of Pounds", axes=F)
axis(1)
axis(2)
abline(v=2010, col="grey", lwd=3, lty=3)
abline(v=2015, col="grey", lwd=3, lty=3)
abline(h=0, col="grey", lwd=3)
points(unique(data$year), earnings.sum, type="l", lwd=4)
points(unique(data$year), earnings.work.infl.sum, type="l", lwd=4, lty=2)
points(unique(data$year), earnings.press.infl.sum, type="l", lwd=4, lty=6)
points(unique(data$year), earnings.speech.infl.sum, type="l", lwd=4, lty=3)
text(2013, 5.75, "All", cex=1.25)
text(2013, 4.65, "Employment", cex=1.25)
text(2013, 0.9, "Press", cex=1.25)
text(2013, 0.2, "Speeches", cex=1.25)

dev.off()



# Panel (b)
setEPS()
postscript("output/paper/fig2b.eps")
par(mar = c(2,3,1,1), mgp=c(2,0.5,0))

plot(unique(data$year), earnings.share, type="n", ylim=c(0, max(earnings.share)), lwd=4, xlab="", ylab="Share of MPs with Outside Income", axes=F)
axis(1)
axis(2)
abline(v=2010, col="grey", lwd=3, lty=3)
abline(v=2015, col="grey", lwd=3, lty=3)
abline(h=0, col="grey", lwd=3)
points(unique(data$year), earnings.share, type="l", lwd=4)
points(unique(data$year), earnings.work.infl.share, type="l", lwd=4, lty=2)
points(unique(data$year), earnings.press.infl.share, type="l", lwd=4, lty=6)
points(unique(data$year), earnings.speech.infl.share, type="l", lwd=4, lty=3)
text(2013, 0.28, "All", cex=1.25)
text(2013, 0.17, "Employment", cex=1.25)
text(2013, 0.1375, "Press", cex=1.25)
text(2013, 0.095, "Speeches", cex=1.25)
dev.off()



# Panel (c)
setEPS()
postscript("output/paper/fig2c.eps")
par(mar = c(2,3,1,1), mgp=c(2,0.5,0))

plot(unique(data$year), earnings.mean.nonull, type="n", ylim=c(0, max(earnings.work.infl.mean.nonull)), lwd=4, xlab="", ylab="Mean Annual Earnings in Pounds", axes=F)
axis(1)
axis(2, at=seq(0, 50000, 10000), labels=format(seq(0, 50000, 10000), big.mark=",", scientific=FALSE)) 
abline(v=2010, col="grey", lwd=3, lty=3)
abline(v=2015, col="grey", lwd=3, lty=3)
abline(h=0, col="grey", lwd=3)
points(unique(data$year), earnings.mean.nonull, type="l", lwd=4)
points(unique(data$year), earnings.work.infl.mean.nonull, type="l", lwd=4, lty=2)
points(unique(data$year), earnings.press.infl.mean.nonull, type="l", lwd=4, lty=6)
points(unique(data$year), earnings.speech.infl.mean.nonull, type="l", lwd=4, lty=3)
text(2013, 32000, "All", cex=1.25)
text(2013, 44500, "Employment", cex=1.25)
text(2013, 10000, "Press", cex=1.25)
text(2013, 6000, "Speeches", cex=1.25)
dev.off()



# Panel (d)
tmp1 <- c(sum(data$job_director), sum(data$job_consultant), sum(data$job_board), sum(data$job_legal), sum(data$job_health), sum(data$job_other))
tmp1 <- (tmp1/sum(tmp1))
tmp2 <- c("Director, Chairman, \n President, Partner", "Consultant, Advisor", "Board Member", "Legal Professional", "Health Care Professional", "Other Professional")
jobtitles <- data.frame(rev(tmp2), rev(tmp1))
colnames(jobtitles) <- c("position", "count")



setEPS()
postscript("output/paper/fig2d.eps", width=5*1.62, height=5)
par(mar = c(3,10,0,1), mgp=c(2,0.5,0))
barplot(jobtitles$count, names.arg=jobtitles$position, las=1, horiz=T, cex.names=1, xlim=c(0,0.40), col="grey", border=NA, xlab="Share")
dev.off()


# Panel (e)
tmp1 <- c(sum(data$ind_thinktank), sum(data$ind_it), sum(data$ind_retail), sum(data$ind_realestate), sum(data$ind_publishing), sum(data$ind_public), sum(data$ind_other), sum(data$ind_oil), sum(data$ind_manufacturing), sum(data$ind_leisure), sum(data$ind_law), sum(data$ind_insurance), sum(data$ind_health), sum(data$ind_foreigngov), sum(data$ind_finance), sum(data$ind_energy), sum(data$ind_education), sum(data$ind_defense), sum(data$ind_consulting), sum(data$ind_ngo), sum(data$ind_transport), sum(data$ind_agriculture)) 
tmp1 <- (tmp1/sum(tmp1))

tmp2 <- c("Think Tank", "Software, IT, Telecommunications", "Retail, Services", "Real Estate, Construction, Infrastructure", "Publishing", "Public Agency", "Other", "Mining, Oil and Gas", "Manufacturing", "Leisure", "Law Firm", "Insurance", "Health Care, Medicine", "Foreign Government", "Finance, Banking", "Energy", "Education", "Defense", "Consulting", "Charity, NGO", "Automotive, Transportation, Logistics", "Agriculture, Food")

industry <- data.frame(rev(tmp2), rev(tmp1))
colnames(industry) <- c("position", "count")

industry <- industry[order(industry$count, decreasing=F),]
industry <- rbind(industry[industry$position=="Other",], industry[industry$position!="Other",])

setEPS()
postscript("output/paper/fig2e.eps", width=5*1.62, height=5)
par(mar = c(3,14.1,0,1), mgp=c(2,0.5,0))
barplot(industry$count, names.arg=industry$position, las=1, horiz=T, cex.names=0.875, xlim=c(0,0.16), col="grey", border=NA, xlab="Share")
dev.off()






##### FIGURE 3


## Minister
ids <- unique(data$id[data$minister==1])
mindata <- data[data$id %in% ids,]

# find matches
compdata <- NULL
mindata$keep <- NA
for(i in 1:length(ids)){
	usedata <- mindata[mindata$id==ids[i],]
	altdata <- data[data$id %!in% ids,]

	altdata <- data.table(altdata)
	match <- altdata[, list(earnings.all.infl.log.1=mean(earnings.all.infl.log.1)), by=year]
	match <- match[match$year %in% usedata$year,]

	mindata$keep[mindata$id==ids[i]] <- ifelse(usedata$year %!in% match$year==F, 1, 0)
	usedata <- usedata[usedata$year %in% match$year==T,]

	match$minister.notyears <- usedata$minister.notyears
	match$minister.years <- usedata$minister.years
	match$minister.yearstoend <- usedata$minister.yearstoend
	compdata <- rbind(compdata, match)
}

mindata <- mindata[mindata$keep==1,]


# Plots
plotvec <- NULL
# 2 years before taking position (full years)
plotvec <- c(plotvec, mean(mindata$earnings.all.infl.log.1[mindata$minister.notyears==-2]))
plotvec <- c(plotvec, mean(mindata$earnings.all.infl.log.1[mindata$minister.notyears==-1]))

# year of taking position
plotvec <- c(plotvec, mean(mindata$earnings.all.infl.log.1[mindata$minister.years==1]))

# 2 years being in position (full years)
plotvec <- c(plotvec, mean(mindata$earnings.all.infl.log.1[mindata$minister.years==2]))
plotvec <- c(plotvec, mean(mindata$earnings.all.infl.log.1[mindata$minister.years==3]))


compvec <- NULL
# 2 years before taking position (full years)
compvec <- c(compvec, mean(compdata$earnings.all.infl.log.1[compdata$minister.notyears==-2]))
compvec <- c(compvec, mean(compdata$earnings.all.infl.log.1[compdata$minister.notyears==-1]))

# year of taking position
compvec <- c(compvec, mean(compdata$earnings.all.infl.log.1[compdata$minister.years==1]))

# 2 years being in position (full years)
compvec <- c(compvec, mean(compdata$earnings.all.infl.log.1[compdata$minister.years==2]))
compvec <- c(compvec, mean(compdata$earnings.all.infl.log.1[compdata$minister.years==3]))


setEPS()
postscript("output/paper/fig3a.eps", width=6, height=3)
par(mar = c(3,3,1,1), mgp=c(2,0.5,0))
plot(c(-2:2), plotvec, ylim=c(0, 6.5), pch=16, cex=2, ylab="Average of Log Earnings", xlab="Years in Office", type="n", axes=F)
axis(1)
axis(2)
abline(v=0, col="darkgrey", lty=2, lwd=5)
lines(c(-2:2), plotvec, lwd=3)
points(c(-2:2), plotvec, pch=16, cex=2.5)
lines(c(-2:2), compvec, lwd=3, col="grey")
points(c(-2:2), compvec, pch=16, cex=2.5, col="grey")
text(0, 6, "Minister, Enter", cex=1.5)
dev.off()


plotvec2 <- NULL
# 2 years before leaving (full years)
plotvec2 <- c(plotvec2, mean(mindata$earnings.all.infl.log.1[mindata$minister.yearstoend==-3]))
plotvec2 <- c(plotvec2, mean(mindata$earnings.all.infl.log.1[mindata$minister.yearstoend==-2]))

# year of leaving
plotvec2 <- c(plotvec2, mean(mindata$earnings.all.infl.log.1[mindata$minister.yearstoend==-1]))

# 2 years after leaving (full years)
plotvec2 <- c(plotvec2, mean(mindata$earnings.all.infl.log.1[mindata$minister.notyears==1]))
plotvec2 <- c(plotvec2, mean(mindata$earnings.all.infl.log.1[mindata$minister.notyears==2]))


compvec2 <- NULL
# 2 years before leaving (full years)
compvec2 <- c(compvec2, mean(compdata$earnings.all.infl.log.1[compdata$minister.yearstoend==-3]))
compvec2 <- c(compvec2, mean(compdata$earnings.all.infl.log.1[compdata$minister.yearstoend==-2]))

# year of leaving
compvec2 <- c(compvec2, mean(compdata$earnings.all.infl.log.1[compdata$minister.yearstoend==-1]))

# 2 years after leaving (full years)
compvec2 <- c(compvec2, mean(compdata$earnings.all.infl.log.1[compdata$minister.notyears==1]))
compvec2 <- c(compvec2, mean(compdata$earnings.all.infl.log.1[compdata$minister.notyears==2]))


setEPS()
postscript("output/paper/fig3b.eps", width=6, height=3)
par(mar = c(3,3,1,1), mgp=c(2,0.5,0))
plot(c(-2:2), plotvec2, ylim=c(0, 6.5), pch=16, cex=2, ylab="Average of Log Earnings", xlab="Years After Office", type="n", axes=F)
axis(1)
axis(2)
abline(v=0, col="darkgrey", lty=2, lwd=5)
lines(c(-2:2), plotvec2, lwd=3)
points(c(-2:2), plotvec2, pch=16, cex=2.5)
lines(c(-2:2), compvec2, lwd=3, col="grey")
points(c(-2:2), compvec2, pch=16, cex=2.5, col="grey")
text(0, 6, "Minister, Leave", cex=1.5)
dev.off()





## Minister of State
ids <- unique(data$id[data$minister.state==1])
mindata <- data[data$id %in% ids,]

# find matches
compdata <- NULL
mindata$keep <- NA
for(i in 1:length(ids)){
	usedata <- mindata[mindata$id==ids[i],]
	altdata <- data[data$id %!in% ids,]

	altdata <- data.table(altdata)
	match <- altdata[, list(earnings.all.infl.log.1=mean(earnings.all.infl.log.1)), by=year]
	match <- match[match$year %in% usedata$year,]

	mindata$keep[mindata$id==ids[i]] <- ifelse(usedata$year %!in% match$year==F, 1, 0)
	usedata <- usedata[usedata$year %in% match$year==T,]

	match$minister.state.notyears <- usedata$minister.state.notyears
	match$minister.state.years <- usedata$minister.state.years
	match$minister.state.yearstoend <- usedata$minister.state.yearstoend
	compdata <- rbind(compdata, match)
}

mindata <- mindata[mindata$keep==1,]


# Plots
plotvec <- NULL
# 2 years before taking position (full years)
plotvec <- c(plotvec, mean(mindata$earnings.all.infl.log.1[mindata$minister.state.notyears==-2]))
plotvec <- c(plotvec, mean(mindata$earnings.all.infl.log.1[mindata$minister.state.notyears==-1]))

# year of taking position
plotvec <- c(plotvec, mean(mindata$earnings.all.infl.log.1[mindata$minister.state.years==1]))

# 2 years being in position (full years)
plotvec <- c(plotvec, mean(mindata$earnings.all.infl.log.1[mindata$minister.state.years==2]))
plotvec <- c(plotvec, mean(mindata$earnings.all.infl.log.1[mindata$minister.state.years==3]))


compvec <- NULL
# 2 years before taking position (full years)
compvec <- c(compvec, mean(compdata$earnings.all.infl.log.1[compdata$minister.state.notyears==-2]))
compvec <- c(compvec, mean(compdata$earnings.all.infl.log.1[compdata$minister.state.notyears==-1]))

# year of taking position
compvec <- c(compvec, mean(compdata$earnings.all.infl.log.1[compdata$minister.state.years==1]))

# 2 years being in position (full years)
compvec <- c(compvec, mean(compdata$earnings.all.infl.log.1[compdata$minister.state.years==2]))
compvec <- c(compvec, mean(compdata$earnings.all.infl.log.1[compdata$minister.state.years==3]))


setEPS()
postscript("output/paper/fig3c.eps", width=6, height=3)
par(mar = c(3,3,1,1), mgp=c(2,0.5,0))
plot(c(-2:2), plotvec, ylim=c(0, 6.5), pch=16, cex=2, ylab="Average of Log Earnings", xlab="Years in Office", type="n", axes=F)
axis(1)
axis(2)
abline(v=0, col="darkgrey", lty=2, lwd=5)
lines(c(-2:2), plotvec, lwd=3)
points(c(-2:2), plotvec, pch=16, cex=2.5)
lines(c(-2:2), compvec, lwd=3, col="grey")
points(c(-2:2), compvec, pch=16, cex=2.5, col="grey")
text(0, 6, "Minister of State, Enter", cex=1.5)
dev.off()


plotvec2 <- NULL
# 2 years before leaving (full years)
plotvec2 <- c(plotvec2, mean(mindata$earnings.all.infl.log.1[mindata$minister.state.yearstoend==-3]))
plotvec2 <- c(plotvec2, mean(mindata$earnings.all.infl.log.1[mindata$minister.state.yearstoend==-2]))

# year of leaving
plotvec2 <- c(plotvec2, mean(mindata$earnings.all.infl.log.1[mindata$minister.state.yearstoend==-1]))

# 2 years after leaving (full years)
plotvec2 <- c(plotvec2, mean(mindata$earnings.all.infl.log.1[mindata$minister.state.notyears==1]))
plotvec2 <- c(plotvec2, mean(mindata$earnings.all.infl.log.1[mindata$minister.state.notyears==2]))


compvec2 <- NULL
# 2 years before leaving (full years)
compvec2 <- c(compvec2, mean(compdata$earnings.all.infl.log.1[compdata$minister.state.yearstoend==-3]))
compvec2 <- c(compvec2, mean(compdata$earnings.all.infl.log.1[compdata$minister.state.yearstoend==-2]))

# year of leaving
compvec2 <- c(compvec2, mean(compdata$earnings.all.infl.log.1[compdata$minister.state.yearstoend==-1]))

# 2 years after leaving (full years)
compvec2 <- c(compvec2, mean(compdata$earnings.all.infl.log.1[compdata$minister.state.notyears==1]))
compvec2 <- c(compvec2, mean(compdata$earnings.all.infl.log.1[compdata$minister.state.notyears==2]))


setEPS()
postscript("output/paper/fig3d.eps", width=6, height=3)
par(mar = c(3,3,1,1), mgp=c(2,0.5,0))
plot(c(-2:2), plotvec2, ylim=c(0, 6.5), pch=16, cex=2, ylab="Average of Log Earnings", xlab="Years After Office", type="n", axes=F)
axis(1)
axis(2)
abline(v=0, col="darkgrey", lty=2, lwd=5)
lines(c(-2:2), plotvec2, lwd=3)
points(c(-2:2), plotvec2, pch=16, cex=2.5)
lines(c(-2:2), compvec2, lwd=3, col="grey")
points(c(-2:2), compvec2, pch=16, cex=2.5, col="grey")
text(0, 6, "Minister of State, Leave", cex=1.5)
dev.off()



## Parliamentary Secretary
ids <- unique(data$id[data$undersec==1])
mindata <- data[data$id %in% ids,]

# find matches
compdata <- NULL
mindata$keep <- NA
for(i in 1:length(ids)){
	usedata <- mindata[mindata$id==ids[i],]
	altdata <- data[data$id %!in% ids,]

	altdata <- data.table(altdata)
	match <- altdata[, list(earnings.all.infl.log.1=mean(earnings.all.infl.log.1)), by=year]
	match <- match[match$year %in% usedata$year,]

	mindata$keep[mindata$id==ids[i]] <- ifelse(usedata$year %!in% match$year==F, 1, 0)
	usedata <- usedata[usedata$year %in% match$year==T,]

	match$undersec.notyears <- usedata$undersec.notyears
	match$undersec.years <- usedata$undersec.years
	match$undersec.yearstoend <- usedata$undersec.yearstoend
	compdata <- rbind(compdata, match)
}

mindata <- mindata[mindata$keep==1,]


# Plots
plotvec <- NULL
# 2 years before taking position (full years)
plotvec <- c(plotvec, mean(mindata$earnings.all.infl.log.1[mindata$undersec.notyears==-2]))
plotvec <- c(plotvec, mean(mindata$earnings.all.infl.log.1[mindata$undersec.notyears==-1]))

# year of taking position
plotvec <- c(plotvec, mean(mindata$earnings.all.infl.log.1[mindata$undersec.years==1]))

# 2 years being in position (full years)
plotvec <- c(plotvec, mean(mindata$earnings.all.infl.log.1[mindata$undersec.years==2]))
plotvec <- c(plotvec, mean(mindata$earnings.all.infl.log.1[mindata$undersec.years==3]))


compvec <- NULL
# 2 years before taking position (full years)
compvec <- c(compvec, mean(compdata$earnings.all.infl.log.1[compdata$undersec.notyears==-2]))
compvec <- c(compvec, mean(compdata$earnings.all.infl.log.1[compdata$undersec.notyears==-1]))

# year of taking position
compvec <- c(compvec, mean(compdata$earnings.all.infl.log.1[compdata$undersec.years==1]))

# 2 years being in position (full years)
compvec <- c(compvec, mean(compdata$earnings.all.infl.log.1[compdata$undersec.years==2]))
compvec <- c(compvec, mean(compdata$earnings.all.infl.log.1[compdata$undersec.years==3]))


setEPS()
postscript("output/paper/fig3e.eps", width=6, height=3)
par(mar = c(3,3,1,1), mgp=c(2,0.5,0))
plot(c(-2:2), plotvec, ylim=c(0, 6.5), pch=16, cex=2, ylab="Average of Log Earnings", xlab="Years in Office", type="n", axes=F)
axis(1)
axis(2)
abline(v=0, col="darkgrey", lty=2, lwd=5)
lines(c(-2:2), plotvec, lwd=3)
points(c(-2:2), plotvec, pch=16, cex=2.5)
lines(c(-2:2), compvec, lwd=3, col="grey")
points(c(-2:2), compvec, pch=16, cex=2.5, col="grey")
text(0, 6, "Parliamentary Secretary, Enter", cex=1.5)
dev.off()


plotvec2 <- NULL
# 2 years before leaving (full years)
plotvec2 <- c(plotvec2, mean(mindata$earnings.all.infl.log.1[mindata$undersec.yearstoend==-3]))
plotvec2 <- c(plotvec2, mean(mindata$earnings.all.infl.log.1[mindata$undersec.yearstoend==-2]))

# year of leaving
plotvec2 <- c(plotvec2, mean(mindata$earnings.all.infl.log.1[mindata$undersec.yearstoend==-1]))

# 2 years after leaving (full years)
plotvec2 <- c(plotvec2, mean(mindata$earnings.all.infl.log.1[mindata$undersec.notyears==1]))
plotvec2 <- c(plotvec2, mean(mindata$earnings.all.infl.log.1[mindata$undersec.notyears==2]))


compvec2 <- NULL
# 2 years before leaving (full years)
compvec2 <- c(compvec2, mean(compdata$earnings.all.infl.log.1[compdata$undersec.yearstoend==-3]))
compvec2 <- c(compvec2, mean(compdata$earnings.all.infl.log.1[compdata$undersec.yearstoend==-2]))

# year of leaving
compvec2 <- c(compvec2, mean(compdata$earnings.all.infl.log.1[compdata$undersec.yearstoend==-1]))

# 2 years after leaving (full years)
compvec2 <- c(compvec2, mean(compdata$earnings.all.infl.log.1[compdata$undersec.notyears==1]))
compvec2 <- c(compvec2, mean(compdata$earnings.all.infl.log.1[compdata$undersec.notyears==2]))


setEPS()
postscript("output/paper/fig3f.eps", width=6, height=3)
par(mar = c(3,3,1,1), mgp=c(2,0.5,0))
plot(c(-2:2), plotvec2, ylim=c(0, 6.5), pch=16, cex=2, ylab="Average of Log Earnings", xlab="Years After Office", type="n", axes=F)
axis(1)
axis(2)
abline(v=0, col="darkgrey", lty=2, lwd=5)
lines(c(-2:2), plotvec2, lwd=3)
points(c(-2:2), plotvec2, pch=16, cex=2.5)
lines(c(-2:2), compvec2, lwd=3, col="grey")
points(c(-2:2), compvec2, pch=16, cex=2.5, col="grey")
text(0, 6, "Parliamentary Secretary, Leave", cex=1.5)
dev.off()




## Shadow Cabinet
ids <- unique(data$id[data$shadow.cabinet==1])
mindata <- data[data$id %in% ids,]

# find matches
compdata <- NULL
mindata$keep <- NA
for(i in 1:length(ids)){
	usedata <- mindata[mindata$id==ids[i],]
	altdata <- data[data$id %!in% ids,]

	altdata <- data.table(altdata)
	match <- altdata[, list(earnings.all.infl.log.1=mean(earnings.all.infl.log.1)), by=year]
	match <- match[match$year %in% usedata$year,]

	mindata$keep[mindata$id==ids[i]] <- ifelse(usedata$year %!in% match$year==F, 1, 0)
	usedata <- usedata[usedata$year %in% match$year==T,]

	match$shadow.cabinet.notyears <- usedata$shadow.cabinet.notyears
	match$shadow.cabinet.years <- usedata$shadow.cabinet.years
	match$shadow.cabinet.yearstoend <- usedata$shadow.cabinet.yearstoend
	compdata <- rbind(compdata, match)
}

mindata <- mindata[mindata$keep==1,]


# Plots
plotvec <- NULL
# 2 years before taking position (full years)
plotvec <- c(plotvec, mean(mindata$earnings.all.infl.log.1[mindata$shadow.cabinet.notyears==-2]))
plotvec <- c(plotvec, mean(mindata$earnings.all.infl.log.1[mindata$shadow.cabinet.notyears==-1]))

# year of taking position
plotvec <- c(plotvec, mean(mindata$earnings.all.infl.log.1[mindata$shadow.cabinet.years==1]))

# 2 years being in position (full years)
plotvec <- c(plotvec, mean(mindata$earnings.all.infl.log.1[mindata$shadow.cabinet.years==2]))
plotvec <- c(plotvec, mean(mindata$earnings.all.infl.log.1[mindata$shadow.cabinet.years==3]))


compvec <- NULL
# 2 years before taking position (full years)
compvec <- c(compvec, mean(compdata$earnings.all.infl.log.1[compdata$shadow.cabinet.notyears==-2]))
compvec <- c(compvec, mean(compdata$earnings.all.infl.log.1[compdata$shadow.cabinet.notyears==-1]))

# year of taking position
compvec <- c(compvec, mean(compdata$earnings.all.infl.log.1[compdata$shadow.cabinet.years==1]))

# 2 years being in position (full years)
compvec <- c(compvec, mean(compdata$earnings.all.infl.log.1[compdata$shadow.cabinet.years==2]))
compvec <- c(compvec, mean(compdata$earnings.all.infl.log.1[compdata$shadow.cabinet.years==3]))


setEPS()
postscript("output/paper/fig3g.eps", width=6, height=3)
par(mar = c(3,3,1,1), mgp=c(2,0.5,0))
plot(c(-2:2), plotvec, ylim=c(0, 6.5), pch=16, cex=2, ylab="Average of Log Earnings", xlab="Years in Office", type="n", axes=F)
axis(1)
axis(2)
abline(v=0, col="darkgrey", lty=2, lwd=5)
lines(c(-2:2), plotvec, lwd=3)
points(c(-2:2), plotvec, pch=16, cex=2.5)
lines(c(-2:2), compvec, lwd=3, col="grey")
points(c(-2:2), compvec, pch=16, cex=2.5, col="grey")
text(0, 6, "Shadow Cabinet, Enter", cex=1.5)
dev.off()


plotvec2 <- NULL
# 2 years before leaving (full years)
plotvec2 <- c(plotvec2, mean(mindata$earnings.all.infl.log.1[mindata$shadow.cabinet.yearstoend==-3]))
plotvec2 <- c(plotvec2, mean(mindata$earnings.all.infl.log.1[mindata$shadow.cabinet.yearstoend==-2]))

# year of leaving
plotvec2 <- c(plotvec2, mean(mindata$earnings.all.infl.log.1[mindata$shadow.cabinet.yearstoend==-1]))

# 2 years after leaving (full years)
plotvec2 <- c(plotvec2, mean(mindata$earnings.all.infl.log.1[mindata$shadow.cabinet.notyears==1]))
plotvec2 <- c(plotvec2, mean(mindata$earnings.all.infl.log.1[mindata$shadow.cabinet.notyears==2]))


compvec2 <- NULL
# 2 years before leaving (full years)
compvec2 <- c(compvec2, mean(compdata$earnings.all.infl.log.1[compdata$shadow.cabinet.yearstoend==-3]))
compvec2 <- c(compvec2, mean(compdata$earnings.all.infl.log.1[compdata$shadow.cabinet.yearstoend==-2]))

# year of leaving
compvec2 <- c(compvec2, mean(compdata$earnings.all.infl.log.1[compdata$shadow.cabinet.yearstoend==-1]))

# 2 years after leaving (full years)
compvec2 <- c(compvec2, mean(compdata$earnings.all.infl.log.1[compdata$shadow.cabinet.notyears==1]))
compvec2 <- c(compvec2, mean(compdata$earnings.all.infl.log.1[compdata$shadow.cabinet.notyears==2]))


setEPS()
postscript("output/paper/fig3h.eps", width=6, height=3)
par(mar = c(3,3,1,1), mgp=c(2,0.5,0))
plot(c(-2:2), plotvec2, ylim=c(0, 6.5), pch=16, cex=2, ylab="Average of Log Earnings", xlab="Years After Office", type="n", axes=F)
axis(1)
axis(2)
abline(v=0, col="darkgrey", lty=2, lwd=5)
lines(c(-2:2), plotvec2, lwd=3)
points(c(-2:2), plotvec2, pch=16, cex=2.5)
lines(c(-2:2), compvec2, lwd=3, col="grey")
points(c(-2:2), compvec2, pch=16, cex=2.5, col="grey")
text(0, 6, "Shadow Cabinet, Leave", cex=1.5)
dev.off()



## Frontbench Team
ids <- unique(data$id[data$frontbench.team==1])
mindata <- data[data$id %in% ids,]

# find matches
compdata <- NULL
mindata$keep <- NA
for(i in 1:length(ids)){
	usedata <- mindata[mindata$id==ids[i],]
	altdata <- data[data$id %!in% ids,]

	altdata <- data.table(altdata)
	match <- altdata[, list(earnings.all.infl.log.1=mean(earnings.all.infl.log.1)), by=year]
	match <- match[match$year %in% usedata$year,]

	mindata$keep[mindata$id==ids[i]] <- ifelse(usedata$year %!in% match$year==F, 1, 0)
	usedata <- usedata[usedata$year %in% match$year==T,]

	match$frontbench.team.notyears <- usedata$frontbench.team.notyears
	match$frontbench.team.years <- usedata$frontbench.team.years
	match$frontbench.team.yearstoend <- usedata$frontbench.team.yearstoend
	compdata <- rbind(compdata, match)
}

mindata <- mindata[mindata$keep==1,]


# Plots
plotvec <- NULL
# 2 years before taking position (full years)
plotvec <- c(plotvec, mean(mindata$earnings.all.infl.log.1[mindata$frontbench.team.notyears==-2]))
plotvec <- c(plotvec, mean(mindata$earnings.all.infl.log.1[mindata$frontbench.team.notyears==-1]))

# year of taking position
plotvec <- c(plotvec, mean(mindata$earnings.all.infl.log.1[mindata$frontbench.team.years==1]))

# 2 years being in position (full years)
plotvec <- c(plotvec, mean(mindata$earnings.all.infl.log.1[mindata$frontbench.team.years==2]))
plotvec <- c(plotvec, mean(mindata$earnings.all.infl.log.1[mindata$frontbench.team.years==3]))


compvec <- NULL
# 2 years before taking position (full years)
compvec <- c(compvec, mean(compdata$earnings.all.infl.log.1[compdata$frontbench.team.notyears==-2]))
compvec <- c(compvec, mean(compdata$earnings.all.infl.log.1[compdata$frontbench.team.notyears==-1]))

# year of taking position
compvec <- c(compvec, mean(compdata$earnings.all.infl.log.1[compdata$frontbench.team.years==1]))

# 2 years being in position (full years)
compvec <- c(compvec, mean(compdata$earnings.all.infl.log.1[compdata$frontbench.team.years==2]))
compvec <- c(compvec, mean(compdata$earnings.all.infl.log.1[compdata$frontbench.team.years==3]))


setEPS()
postscript("output/paper/fig3i.eps", width=6, height=3)
par(mar = c(3,3,1,1), mgp=c(2,0.5,0))
plot(c(-2:2), plotvec, ylim=c(0, 6.5), pch=16, cex=2, ylab="Average of Log Earnings", xlab="Years in Office", type="n", axes=F)
axis(1)
axis(2)
abline(v=0, col="darkgrey", lty=2, lwd=5)
lines(c(-2:2), plotvec, lwd=3)
points(c(-2:2), plotvec, pch=16, cex=2.5)
lines(c(-2:2), compvec, lwd=3, col="grey")
points(c(-2:2), compvec, pch=16, cex=2.5, col="grey")
text(0, 6, "Frontbench Team, Enter", cex=1.5)
dev.off()


plotvec2 <- NULL
# 2 years before leaving (full years)
plotvec2 <- c(plotvec2, mean(mindata$earnings.all.infl.log.1[mindata$frontbench.team.yearstoend==-3]))
plotvec2 <- c(plotvec2, mean(mindata$earnings.all.infl.log.1[mindata$frontbench.team.yearstoend==-2]))

# year of leaving
plotvec2 <- c(plotvec2, mean(mindata$earnings.all.infl.log.1[mindata$frontbench.team.yearstoend==-1]))

# 2 years after leaving (full years)
plotvec2 <- c(plotvec2, mean(mindata$earnings.all.infl.log.1[mindata$frontbench.team.notyears==1]))
plotvec2 <- c(plotvec2, mean(mindata$earnings.all.infl.log.1[mindata$frontbench.team.notyears==2]))


compvec2 <- NULL
# 2 years before leaving (full years)
compvec2 <- c(compvec2, mean(compdata$earnings.all.infl.log.1[compdata$frontbench.team.yearstoend==-3]))
compvec2 <- c(compvec2, mean(compdata$earnings.all.infl.log.1[compdata$frontbench.team.yearstoend==-2]))

# year of leaving
compvec2 <- c(compvec2, mean(compdata$earnings.all.infl.log.1[compdata$frontbench.team.yearstoend==-1]))

# 2 years after leaving (full years)
compvec2 <- c(compvec2, mean(compdata$earnings.all.infl.log.1[compdata$frontbench.team.notyears==1]))
compvec2 <- c(compvec2, mean(compdata$earnings.all.infl.log.1[compdata$frontbench.team.notyears==2]))


setEPS()
postscript("output/paper/fig3j.eps", width=6, height=3)
par(mar = c(3,3,1,1), mgp=c(2,0.5,0))
plot(c(-2:2), plotvec2, ylim=c(0, 6.5), pch=16, cex=2, ylab="Average of Log Earnings", xlab="Years After Office", type="n", axes=F)
axis(1)
axis(2)
abline(v=0, col="darkgrey", lty=2, lwd=5)
lines(c(-2:2), plotvec2, lwd=3)
points(c(-2:2), plotvec2, pch=16, cex=2.5)
lines(c(-2:2), compvec2, lwd=3, col="grey")
points(c(-2:2), compvec2, pch=16, cex=2.5, col="grey")
text(0, 6, "Frontbench Team, Leave", cex=1.5)
dev.off()




## Committee Chair
ids <- unique(data$id[data$com.chair==1])
mindata <- data[data$id %in% ids,]

# find matches
compdata <- NULL
mindata$keep <- NA
for(i in 1:length(ids)){
	usedata <- mindata[mindata$id==ids[i],]
	altdata <- data[data$id %!in% ids,]

	altdata <- data.table(altdata)
	match <- altdata[, list(earnings.all.infl.log.1=mean(earnings.all.infl.log.1)), by=year]
	match <- match[match$year %in% usedata$year,]

	mindata$keep[mindata$id==ids[i]] <- ifelse(usedata$year %!in% match$year==F, 1, 0)
	usedata <- usedata[usedata$year %in% match$year==T,]

	match$com.chair.notyears <- usedata$com.chair.notyears
	match$com.chair.years <- usedata$com.chair.years
	match$com.chair.yearstoend <- usedata$com.chair.yearstoend
	compdata <- rbind(compdata, match)
}

mindata <- mindata[mindata$keep==1,]


# Plots
plotvec <- NULL
# 2 years before taking position (full years)
plotvec <- c(plotvec, mean(mindata$earnings.all.infl.log.1[mindata$com.chair.notyears==-2]))
plotvec <- c(plotvec, mean(mindata$earnings.all.infl.log.1[mindata$com.chair.notyears==-1]))

# year of taking position
plotvec <- c(plotvec, mean(mindata$earnings.all.infl.log.1[mindata$com.chair.years==1]))

# 2 years being in position (full years)
plotvec <- c(plotvec, mean(mindata$earnings.all.infl.log.1[mindata$com.chair.years==2]))
plotvec <- c(plotvec, mean(mindata$earnings.all.infl.log.1[mindata$com.chair.years==3]))


compvec <- NULL
# 2 years before taking position (full years)
compvec <- c(compvec, mean(compdata$earnings.all.infl.log.1[compdata$com.chair.notyears==-2]))
compvec <- c(compvec, mean(compdata$earnings.all.infl.log.1[compdata$com.chair.notyears==-1]))

# year of taking position
compvec <- c(compvec, mean(compdata$earnings.all.infl.log.1[compdata$com.chair.years==1]))

# 2 years being in position (full years)
compvec <- c(compvec, mean(compdata$earnings.all.infl.log.1[compdata$com.chair.years==2]))
compvec <- c(compvec, mean(compdata$earnings.all.infl.log.1[compdata$com.chair.years==3]))


setEPS()
postscript("output/paper/fig3k.eps", width=6, height=3)
par(mar = c(3,3,1,1), mgp=c(2,0.5,0))
plot(c(-2:2), plotvec, ylim=c(0, 6.5), pch=16, cex=2, ylab="Average of Log Earnings", xlab="Years in Office", type="n", axes=F)
axis(1)
axis(2)
abline(v=0, col="darkgrey", lty=2, lwd=5)
lines(c(-2:2), plotvec, lwd=3)
points(c(-2:2), plotvec, pch=16, cex=2.5)
lines(c(-2:2), compvec, lwd=3, col="grey")
points(c(-2:2), compvec, pch=16, cex=2.5, col="grey")
text(0, 6, "Committee Chair, Enter", cex=1.5)
dev.off()


plotvec2 <- NULL
# 2 years before leaving (full years)
plotvec2 <- c(plotvec2, mean(mindata$earnings.all.infl.log.1[mindata$com.chair.yearstoend==-3]))
plotvec2 <- c(plotvec2, mean(mindata$earnings.all.infl.log.1[mindata$com.chair.yearstoend==-2]))

# year of leaving
plotvec2 <- c(plotvec2, mean(mindata$earnings.all.infl.log.1[mindata$com.chair.yearstoend==-1]))

# 2 years after leaving (full years)
plotvec2 <- c(plotvec2, mean(mindata$earnings.all.infl.log.1[mindata$com.chair.notyears==1]))
plotvec2 <- c(plotvec2, mean(mindata$earnings.all.infl.log.1[mindata$com.chair.notyears==2]))


compvec2 <- NULL
# 2 years before leaving (full years)
compvec2 <- c(compvec2, mean(compdata$earnings.all.infl.log.1[compdata$com.chair.yearstoend==-3]))
compvec2 <- c(compvec2, mean(compdata$earnings.all.infl.log.1[compdata$com.chair.yearstoend==-2]))

# year of leaving
compvec2 <- c(compvec2, mean(compdata$earnings.all.infl.log.1[compdata$com.chair.yearstoend==-1]))

# 2 years after leaving (full years)
compvec2 <- c(compvec2, mean(compdata$earnings.all.infl.log.1[compdata$com.chair.notyears==1]))
compvec2 <- c(compvec2, mean(compdata$earnings.all.infl.log.1[compdata$com.chair.notyears==2]))


setEPS()
postscript("output/paper/fig3l.eps", width=6, height=3)
par(mar = c(3,3,1,1), mgp=c(2,0.5,0))
plot(c(-2:2), plotvec2, ylim=c(0, 6.5), pch=16, cex=2, ylab="Average of Log Earnings", xlab="Years After Office", type="n", axes=F)
axis(1)
axis(2)
abline(v=0, col="darkgrey", lty=2, lwd=5)
lines(c(-2:2), plotvec2, lwd=3)
points(c(-2:2), plotvec2, pch=16, cex=2.5)
lines(c(-2:2), compvec2, lwd=3, col="grey")
points(c(-2:2), compvec2, pch=16, cex=2.5, col="grey")
text(0, 6, "Committee Chair, Leave", cex=1.5)
dev.off()



## Committee Member
ids <- unique(data$id[data$com.member==1])
mindata <- data[data$id %in% ids,]

# find matches
compdata <- NULL
mindata$keep <- NA
for(i in 1:length(ids)){
	usedata <- mindata[mindata$id==ids[i],]
	altdata <- data[data$id %!in% ids,]

	altdata <- data.table(altdata)
	match <- altdata[, list(earnings.all.infl.log.1=mean(earnings.all.infl.log.1)), by=year]
	match <- match[match$year %in% usedata$year,]

	mindata$keep[mindata$id==ids[i]] <- ifelse(usedata$year %!in% match$year==F, 1, 0)
	usedata <- usedata[usedata$year %in% match$year==T,]

	match$com.member.notyears <- usedata$com.member.notyears
	match$com.member.years <- usedata$com.member.years
	match$com.member.yearstoend <- usedata$com.member.yearstoend
	compdata <- rbind(compdata, match)
}

mindata <- mindata[mindata$keep==1,]


# Plots
plotvec <- NULL
# 2 years before taking position (full years)
plotvec <- c(plotvec, mean(mindata$earnings.all.infl.log.1[mindata$com.member.notyears==-2]))
plotvec <- c(plotvec, mean(mindata$earnings.all.infl.log.1[mindata$com.member.notyears==-1]))

# year of taking position
plotvec <- c(plotvec, mean(mindata$earnings.all.infl.log.1[mindata$com.member.years==1]))

# 2 years being in position (full years)
plotvec <- c(plotvec, mean(mindata$earnings.all.infl.log.1[mindata$com.member.years==2]))
plotvec <- c(plotvec, mean(mindata$earnings.all.infl.log.1[mindata$com.member.years==3]))


compvec <- NULL
# 2 years before taking position (full years)
compvec <- c(compvec, mean(compdata$earnings.all.infl.log.1[compdata$com.member.notyears==-2]))
compvec <- c(compvec, mean(compdata$earnings.all.infl.log.1[compdata$com.member.notyears==-1]))

# year of taking position
compvec <- c(compvec, mean(compdata$earnings.all.infl.log.1[compdata$com.member.years==1]))

# 2 years being in position (full years)
compvec <- c(compvec, mean(compdata$earnings.all.infl.log.1[compdata$com.member.years==2]))
compvec <- c(compvec, mean(compdata$earnings.all.infl.log.1[compdata$com.member.years==3]))


setEPS()
postscript("output/paper/fig3m.eps", width=6, height=3)
par(mar = c(3,3,1,1), mgp=c(2,0.5,0))
plot(c(-2:2), plotvec, ylim=c(0, 6.5), pch=16, cex=2, ylab="Average of Log Earnings", xlab="Years in Office", type="n", axes=F)
axis(1)
axis(2)
abline(v=0, col="darkgrey", lty=2, lwd=5)
lines(c(-2:2), plotvec, lwd=3)
points(c(-2:2), plotvec, pch=16, cex=2.5)
lines(c(-2:2), compvec, lwd=3, col="grey")
points(c(-2:2), compvec, pch=16, cex=2.5, col="grey")
text(0, 6, "Committee Member, Enter", cex=1.5)
dev.off()


plotvec2 <- NULL
# 2 years before leaving (full years)
plotvec2 <- c(plotvec2, mean(mindata$earnings.all.infl.log.1[mindata$com.member.yearstoend==-3]))
plotvec2 <- c(plotvec2, mean(mindata$earnings.all.infl.log.1[mindata$com.member.yearstoend==-2]))

# year of leaving
plotvec2 <- c(plotvec2, mean(mindata$earnings.all.infl.log.1[mindata$com.member.yearstoend==-1]))

# 2 years after leaving (full years)
plotvec2 <- c(plotvec2, mean(mindata$earnings.all.infl.log.1[mindata$com.member.notyears==1]))
plotvec2 <- c(plotvec2, mean(mindata$earnings.all.infl.log.1[mindata$com.member.notyears==2]))


compvec2 <- NULL
# 2 years before leaving (full years)
compvec2 <- c(compvec2, mean(compdata$earnings.all.infl.log.1[compdata$com.member.yearstoend==-3]))
compvec2 <- c(compvec2, mean(compdata$earnings.all.infl.log.1[compdata$com.member.yearstoend==-2]))

# year of leaving
compvec2 <- c(compvec2, mean(compdata$earnings.all.infl.log.1[compdata$com.member.yearstoend==-1]))

# 2 years after leaving (full years)
compvec2 <- c(compvec2, mean(compdata$earnings.all.infl.log.1[compdata$com.member.notyears==1]))
compvec2 <- c(compvec2, mean(compdata$earnings.all.infl.log.1[compdata$com.member.notyears==2]))


setEPS()
postscript("output/paper/fig3n.eps", width=6, height=3)
par(mar = c(3,3,1,1), mgp=c(2,0.5,0))
plot(c(-2:2), plotvec2, ylim=c(0, 6.5), pch=16, cex=2, ylab="Average of Log Earnings", xlab="Years After Office", type="n", axes=F)
axis(1)
axis(2)
abline(v=0, col="darkgrey", lty=2, lwd=5)
lines(c(-2:2), plotvec2, lwd=3)
points(c(-2:2), plotvec2, pch=16, cex=2.5)
lines(c(-2:2), compvec2, lwd=3, col="grey")
points(c(-2:2), compvec2, pch=16, cex=2.5, col="grey")
text(0, 6, "Committee Member, Leave", cex=1.5)
dev.off()








##### TABLE 1

# all
m1 <- felm(earnings.all.infl.log.1 ~ minister + minister.state + undersec + shadow.cabinet + frontbench.team + com.chair + com.member + minister.post + minister.state.post + undersec.post + shadow.cabinet.post + frontbench.team.post + com.chair.post + com.member.post + enter + leave | year + id | 0 | id, data=data)
summary(m1)

# work
m2 <- felm(earnings.work.infl.log.1 ~ minister + minister.state + undersec + shadow.cabinet + frontbench.team + com.chair + com.member + minister.post + minister.state.post + undersec.post + shadow.cabinet.post + frontbench.team.post + com.chair.post + com.member.post + enter + leave | year + id | 0 | id, data=data)
summary(m2)

# press
m3 <- felm(earnings.press.infl.log.1 ~ minister + minister.state + undersec + shadow.cabinet + frontbench.team + com.chair + com.member + minister.post + minister.state.post + undersec.post + shadow.cabinet.post + frontbench.team.post + com.chair.post + com.member.post + enter + leave | year + id | 0 | id, data=data)
summary(m3)

# speech
m4 <- felm(earnings.speech.infl.log.1 ~ minister + minister.state + undersec + shadow.cabinet + frontbench.team + com.chair + com.member + minister.post + minister.state.post + undersec.post + shadow.cabinet.post + frontbench.team.post + com.chair.post + com.member.post + enter + leave | year + id | 0 | id, data=data)
summary(m4)


stargazer(m1, m2, m3, m4,
	dep.var.labels=c("Logged Earnings Total", "Logged Earnings Regular Employment", "Logged Earnings Press", "Logged Earnings Speeches"),
	covariate.labels=c("Minister", "Minister of State", "Parliamentary Secretary", "Shadow Cabinet", "Frontbench Team", "Committee Chair", "Committee Member", "Post-Minister", "Post-Minister of State", "Post-Parliamentary Secretary", "Post-Shadow Cabinet", "Post-Frontbench Team", "Post-Committee Chair", "Post-Committee Member", "Enter Office", "Leave Office"), 
	no.space=T,
	out="output/paper/tab1.tex")

length(unique(m1$fe[[2]]))
length(unique(m2$fe[[2]]))
length(unique(m3$fe[[2]]))
length(unique(m4$fe[[2]]))

linearHypothesis(m1, "minister.state = minister.state.post")
linearHypothesis(m1, "undersec = undersec.post")


# substantive effect size for ministers
ids <- unique(data$id[data$minister==1])
mindata <- data[data$id %in% ids,]
beforedata <- mindata[mindata$minister==0 & mindata$minister.post==0,]
meanbefore <- mean(beforedata$earnings.all.infl)

meanbefore
meanbefore*(exp(1)^(m1$coef[rownames(m1$coef)=="minister"]))
meanbefore*(exp(1)^(m1$coef[rownames(m1$coef)=="minister.post"]))


# substantive effect size for ministers of state
ids <- unique(data$id[data$minister.state==1])
mindata <- data[data$id %in% ids,]
beforedata <- mindata[mindata$minister.state==0 & mindata$minister.state.post==0,]
meanbefore <- mean(beforedata$earnings.all.infl)

meanbefore
meanbefore*(exp(1)^(m1$coef[rownames(m1$coef)=="minister.state"]))
meanbefore*(exp(1)^(m1$coef[rownames(m1$coef)=="minister.state.post"]))


# substantive effect size for parliamentary secretaries
ids <- unique(data$id[data$undersec==1])
mindata <- data[data$id %in% ids,]
beforedata <- mindata[mindata$undersec==0 & mindata$undersec.post==0,]
meanbefore <- mean(beforedata$earnings.all.infl)

meanbefore
meanbefore*(exp(1)^(m1$coef[rownames(m1$coef)=="undersec"]))
meanbefore*(exp(1)^(m1$coef[rownames(m1$coef)=="undersec.post"]))


# substantive effect size for shadow cabinet
ids <- unique(data$id[data$shadow.cabinet==1])
mindata <- data[data$id %in% ids,]
beforedata <- mindata[mindata$shadow.cabinet==0 & mindata$shadow.cabinet.post==0,]
meanbefore <- mean(beforedata$earnings.all.infl)

meanbefore
meanbefore*(exp(1)^(m1$coef[rownames(m1$coef)=="shadow.cabinet"]))
meanbefore*(exp(1)^(m1$coef[rownames(m1$coef)=="shadow.cabinet.post"]))


# substantive effect size for frontbench team
ids <- unique(data$id[data$frontbench.team==1])
mindata <- data[data$id %in% ids,]
beforedata <- mindata[mindata$frontbench.team==0 & mindata$frontbench.team.post==0,]
meanbefore <- mean(beforedata$earnings.all.infl)

meanbefore
meanbefore*(exp(1)^(m1$coef[rownames(m1$coef)=="frontbench.team"]))
meanbefore*(exp(1)^(m1$coef[rownames(m1$coef)=="frontbench.team.post"]))


# substantive effect size for committee chair
ids <- unique(data$id[data$com.chair==1])
mindata <- data[data$id %in% ids,]
beforedata <- mindata[mindata$com.chair==0 & mindata$com.chair.post==0,]
meanbefore <- mean(beforedata$earnings.all.infl)

meanbefore
meanbefore*(exp(1)^(m1$coef[rownames(m1$coef)=="com.chair"]))
meanbefore*(exp(1)^(m1$coef[rownames(m1$coef)=="com.chair.post"]))


# substantive effect size for comittee member
ids <- unique(data$id[data$com.member==1])
mindata <- data[data$id %in% ids,]
beforedata <- mindata[mindata$com.member==0 & mindata$com.member.post==0,]
meanbefore <- mean(beforedata$earnings.all.infl)

meanbefore
meanbefore*(exp(1)^(m1$coef[rownames(m1$coef)=="com.member"]))
meanbefore*(exp(1)^(m1$coef[rownames(m1$coef)=="com.member.post"]))




##### TABLE 2

# How many do leave right away? (this is in text, not table)
data <- data.table(data)

# minister
ids <- unique(data$id[data$minister==1])

usedata <- data[data$id %in% ids,]

usedata$pos.leave <- usedata$minister * usedata$year
usedata$office.leave <- usedata$leave * usedata$year

usedata <- usedata[, list(pos.leave=max(pos.leave), office.leave=max(office.leave)), by=id]
usedata$office.leave <- ifelse(usedata$office.leave==0, 2040, usedata$office.leave)
usedata$yearstoleave <- usedata$office.leave - usedata$pos.leave
usedata$yearstoleave <- ifelse(usedata$yearstoleave>10, "never", usedata$yearstoleave)


table(usedata$yearstoleave)
table(usedata$yearstoleave[usedata$pos.leave<2016])


# minister.state
ids <- unique(data$id[data$minister.state==1])

usedata <- data[data$id %in% ids,]

usedata$pos.leave <- usedata$minister.state * usedata$year
usedata$office.leave <- usedata$leave * usedata$year

usedata <- usedata[, list(pos.leave=max(pos.leave), office.leave=max(office.leave)), by=id]
usedata$office.leave <- ifelse(usedata$office.leave==0, 2040, usedata$office.leave)
usedata$yearstoleave <- usedata$office.leave - usedata$pos.leave
usedata$yearstoleave <- ifelse(usedata$yearstoleave>10, "never", usedata$yearstoleave)

table(usedata$yearstoleave)
table(usedata$yearstoleave[usedata$pos.leave<2016])


# undersec
ids <- unique(data$id[data$undersec==1])

usedata <- data[data$id %in% ids,]

usedata$pos.leave <- usedata$undersec * usedata$year
usedata$office.leave <- usedata$leave * usedata$year

usedata <- usedata[, list(pos.leave=max(pos.leave), office.leave=max(office.leave)), by=id]
usedata$office.leave <- ifelse(usedata$office.leave==0, 2040, usedata$office.leave)
usedata$yearstoleave <- usedata$office.leave - usedata$pos.leave
usedata$yearstoleave <- ifelse(usedata$yearstoleave>10, "never", usedata$yearstoleave)

table(usedata$yearstoleave)
table(usedata$yearstoleave[usedata$pos.leave<2016])



# Do those that leave earlier have more jobs? (this is in Table)
load("data/gov_jobs.rda")


subdata <- jobdata[is.na(jobdata$leave.minister)==F,]
subdata$post.minister.2 <- ifelse(is.na(subdata$post.minister.2)==T, 0, subdata$post.minister.2)
subdata$post.minister.3 <- ifelse(is.na(subdata$post.minister.3)==T, 0, subdata$post.minister.3)
subdata$post <- subdata$post.minister.1 + subdata$post.minister.2 + subdata$post.minister.3
subdata$yearstoleave <- subdata$leave.mp - subdata$leave.minister

mean(subdata$post[subdata$yearstoleave<=0])
mean(subdata$post[subdata$yearstoleave>0])

t1 <- t.test(subdata$post[subdata$yearstoleave<=0], subdata$post[subdata$yearstoleave>0])


subdata <- jobdata[is.na(jobdata$leave.minister.state)==F,]
subdata$post.minister.state.2 <- ifelse(is.na(subdata$post.minister.state.2)==T, 0, subdata$post.minister.state.2)
subdata$post.minister.state.3 <- ifelse(is.na(subdata$post.minister.state.3)==T, 0, subdata$post.minister.state.3)
subdata$post <- subdata$post.minister.state.1 + subdata$post.minister.state.2 + subdata$post.minister.state.3
subdata$yearstoleave <- subdata$leave.mp - subdata$leave.minister.state

mean(subdata$post[subdata$yearstoleave<=0])
mean(subdata$post[subdata$yearstoleave>0])

t2 <- t.test(subdata$post[subdata$yearstoleave<=0], subdata$post[subdata$yearstoleave>0])


subdata <- jobdata[is.na(jobdata$leave.undersec)==F,]
subdata$post.undersec.2 <- ifelse(is.na(subdata$post.undersec.2)==T, 0, subdata$post.undersec.2)
subdata$post.undersec.3 <- ifelse(is.na(subdata$post.undersec.3)==T, 0, subdata$post.undersec.3)
subdata$post <- subdata$post.undersec.1 + subdata$post.undersec.2 + subdata$post.undersec.3
subdata$yearstoleave <- subdata$leave.mp - subdata$leave.undersec

mean(subdata$post[subdata$yearstoleave<=0])
mean(subdata$post[subdata$yearstoleave>0])

t3 <- t.test(subdata$post[subdata$yearstoleave<=0], subdata$post[subdata$yearstoleave>0])



outtable <- xtable(rbind(c("Minister", round(t1$estimate, 2), round(t1$p.value, 2)), c("Minister of State", round(t2$estimate, 2), round(t2$p.value, 2)), c("Parliamentary Secretary", round(t3$estimate, 2), round(t3$p.value, 2))))
print(outtable, file="output/paper/tab2.tex")





##### FIGURE 4

m6 <- m <- felm(earnings.all.infl.log.1 ~ minister + minister.state + undersec + shadow.cabinet + frontbench.team + com.chair + selcom.business + selcom.local + selcom.culture + selcom.defence + selcom.education + selcom.food.rural + selcom.foreign.affairs + selcom.health + selcom.home.affairs + selcom.int.dev + selcom.international.trade + selcom.justice + selcom.northern.ireland + selcom.science + selcom.scottland + selcom.transport + selcom.treasury + selcom.wales + selcom.work.pensions + selcom.energy.climatechange + selcom.environmental.audit + selcom.european.scrutiny + selcom.liaison + selcom.public.accounts + selcom.public.administration + selcom.armsexport.control + selcom.regulatory.reform + selcom.stat.instr + selcom.women + selcom.petitions + selcom.administration + selcom.backbench + selcom.finance.services + selcom.allowances + selcom.standards.priv + selcom.procedure + selcom.selection + com.house.commons + com.public.accounts + com.electoral.commission + com.parl.standards + com.ecclesiastical + com.intelligence.security + minister.post + minister.state.post + undersec.post + shadow.cabinet.post + frontbench.team.post + com.chair.post + selcom.business.post + selcom.local.post + selcom.culture.post + selcom.defence.post + selcom.education.post + selcom.food.rural.post + selcom.foreign.affairs.post + selcom.health.post + selcom.home.affairs.post + selcom.int.dev.post + selcom.international.trade.post + selcom.justice.post + selcom.northern.ireland.post + selcom.science.post + selcom.scottland.post + selcom.transport.post + selcom.treasury.post + selcom.wales.post + selcom.work.pensions.post + selcom.energy.climatechange.post + selcom.environmental.audit.post + selcom.european.scrutiny.post + selcom.liaison.post + selcom.public.accounts.post + selcom.public.administration.post + selcom.armsexport.control.post + selcom.regulatory.reform.post + selcom.stat.instr.post + selcom.women.post + selcom.petitions.post + selcom.administration.post + selcom.backbench.post + selcom.finance.services.post + selcom.allowances.post + selcom.standards.priv.post + selcom.procedure.post + selcom.selection.post + com.house.commons.post + com.public.accounts.post + com.electoral.commission.post + com.parl.standards.post + com.ecclesiastical.post + com.intelligence.security.post + enter + leave | year + id | 0 | id, data=data)
summary(m6)



data1 <- data.frame(rownames(m$coefficients), m$coefficients, m$coefficients+qnorm(0.025)*sqrt(diag(m$clustervcv)), m$coefficients+qnorm(0.975)*sqrt(diag(m$clustervcv)))
colnames(data1) <- c("var", "coef", "ci_lower", "ci_upper")


data.cur <- data1[7:49,]

data.cur$name <- c("Business, Innovation and Skills", "Communities and Local Government", "Culture, Media and Sport", "Defense", "Education", "Food and Rural Affairs", "Foreign Affairs", "Health", "Home Affairs", "International Development", "International Trade", "Justice", "Northern Ireland Affairs", "Science", "Scottish Affairs", "Transport", "Treasury", "Welsh Affairs", "Work and Pensions", "Energy and Climate Change", "Environmental Audit", "European Scrutiny", "Liaison", "Public Accounts", "Public Administration", "Arms Export Controls", "Regulatory Reform", "Statutory Instruments", "Women and Equalities", "Petitions", "Administration", "Backbench Business", "Finance and Services", "Members' Allowances", "Standards and Privileges", "Procedure", "Selection", "House of Commons Commission", "Public Accounts Commission", "Electoral Commission", "Parliamentary Standards", "Ecclesiastical", "Intelligence and Security")

data.cur <- data.cur[order(data.cur$coef),]


setEPS()
postscript("output/paper/fig4.eps", width=8*1.62, height=8)
par(mar = c(4,14,1,1), mgp=c(3,1,0))
plot(data.cur$coef, c(1:length(data.cur$coef)), type="n", xlim=c(min(data.cur$ci_lower, na.rm=T), max(data.cur$ci_upper, na.rm=T)), ylim=c(1,length(data.cur$coef)), axes=F, ylab="", xlab="Coefficients")
axis(2, at=c(1:length(data.cur$coef)), data.cur$name, cex.axis=0.9, las=2)
axis(1, at=-5:3, -5:3)

abline(v=0, col="lightgrey", lwd=2)
abline(h=c(1:length(data.cur$coef)), col="lightgrey", lwd=0.7)

points(data.cur$coef, c(1:length(data.cur$coef)), pch=16, cex=1.2)
for(i in 1:length(data.cur$coef)){
	lines(c(data.cur$ci_lower[i], data.cur$ci_upper[i]), c(i,i), lwd=2.5)
}
dev.off()




# drop those with NA for linearHypotheiss
m6a <- felm(earnings.all.infl.log.1 ~ minister + minister.state + undersec + shadow.cabinet + frontbench.team + com.chair + selcom.business + selcom.local + selcom.culture + selcom.defence + selcom.education + selcom.food.rural + selcom.foreign.affairs + selcom.health + selcom.home.affairs + selcom.int.dev + selcom.international.trade + selcom.justice + selcom.northern.ireland + selcom.science + selcom.scottland + selcom.transport + selcom.treasury + selcom.wales + selcom.work.pensions + selcom.energy.climatechange + selcom.environmental.audit + selcom.european.scrutiny + selcom.liaison + selcom.public.accounts + selcom.public.administration + selcom.armsexport.control + selcom.regulatory.reform + selcom.stat.instr + selcom.women + selcom.petitions + selcom.administration + selcom.backbench + selcom.finance.services + selcom.allowances + selcom.standards.priv + selcom.procedure + selcom.selection + com.house.commons + com.public.accounts + com.electoral.commission + com.parl.standards + com.ecclesiastical + com.intelligence.security + minister.post + minister.state.post + undersec.post + shadow.cabinet.post + frontbench.team.post + com.chair.post + selcom.business.post + selcom.local.post + selcom.culture.post + selcom.defence.post + selcom.education.post + selcom.food.rural.post + selcom.foreign.affairs.post + selcom.health.post + selcom.home.affairs.post + selcom.int.dev.post + selcom.justice.post + selcom.northern.ireland.post + selcom.science.post + selcom.scottland.post + selcom.transport.post + selcom.treasury.post + selcom.wales.post + selcom.work.pensions.post + selcom.energy.climatechange.post + selcom.environmental.audit.post + selcom.european.scrutiny.post + selcom.liaison.post + selcom.public.accounts.post + selcom.public.administration.post + selcom.armsexport.control.post + selcom.regulatory.reform.post + selcom.stat.instr.post + selcom.women.post + selcom.petitions.post + selcom.administration.post + selcom.backbench.post + selcom.finance.services.post + selcom.standards.priv.post + selcom.procedure.post + selcom.selection.post + com.house.commons.post + com.public.accounts.post + com.electoral.commission.post + com.parl.standards.post + com.ecclesiastical.post + com.intelligence.security.post + enter + leave | year + id | 0 | id, data=data)
summary(m6a)


linearHypothesis(m6a, c("selcom.business=0", "selcom.local=0", "selcom.culture=0", "selcom.defence=0", "selcom.education=0", "selcom.food.rural=0", "selcom.foreign.affairs=0", "selcom.health=0", "selcom.home.affairs=0", "selcom.int.dev=0", "selcom.international.trade=0", "selcom.justice=0", "selcom.northern.ireland=0", "selcom.science=0", "selcom.scottland=0", "selcom.transport=0", "selcom.treasury=0", "selcom.wales=0", "selcom.work.pensions=0", "selcom.energy.climatechange=0", "selcom.environmental.audit=0", "selcom.european.scrutiny=0", "selcom.liaison=0", "selcom.public.accounts=0", "selcom.public.administration=0", "selcom.armsexport.control=0", "selcom.regulatory.reform=0", "selcom.stat.instr=0", "selcom.women=0", "selcom.petitions=0", "selcom.administration=0", "selcom.backbench=0", "selcom.finance.services=0", "selcom.allowances=0", "selcom.standards.priv=0", "selcom.procedure=0", "selcom.selection=0", "com.house.commons=0", "com.public.accounts=0", "com.electoral.commission=0", "com.parl.standards=0", "com.ecclesiastical=0", "com.intelligence.security=0"), test="F")





##### FIGURE 5

### (a) Job Titles
data.minister.post <- NULL

m7a <- m <- felm(jobcat_board ~ minister + minister.state + undersec + shadow.cabinet + frontbench.team + com.chair + com.member + minister.post + minister.state.post + undersec.post + shadow.cabinet.post + frontbench.team.post + com.chair.post + com.member.post + enter + leave | year + id | 0 | id, data=data)
summary(m7a)

data1 <- data.frame("Board Member", m$coefficients, m$coefficients+qnorm(0.025)*sqrt(diag(m$clustervcv)), m$coefficients+qnorm(0.975)*sqrt(diag(m$clustervcv)))
colnames(data1) <- c("job", "coef", "ci_lower", "ci_upper")
data.minister.post <- rbind(data1[which(rownames(data1)=="minister.post"),], data.minister.post)


m7b <- m <- felm(jobcat_consultant ~ minister + minister.state + undersec + shadow.cabinet + frontbench.team + com.chair + com.member + minister.post + minister.state.post + undersec.post + shadow.cabinet.post + frontbench.team.post + com.chair.post + com.member.post + enter + leave | year + id | 0 | id, data=data)
summary(m7b)

data1 <- data.frame("Consultant,\nAdvisor", m$coefficients, m$coefficients+qnorm(0.025)*sqrt(diag(m$clustervcv)), m$coefficients+qnorm(0.975)*sqrt(diag(m$clustervcv)))
colnames(data1) <- c("job", "coef", "ci_lower", "ci_upper")
data.minister.post <- rbind(data1[which(rownames(data1)=="minister.post"),], data.minister.post)


m7c <- m <- felm(jobcat_director ~ minister + minister.state + undersec + shadow.cabinet + frontbench.team + com.chair + com.member + minister.post + minister.state.post + undersec.post + shadow.cabinet.post + frontbench.team.post + com.chair.post + com.member.post + enter + leave | year + id | 0 | id, data=data)
summary(m7c)

data1 <- data.frame("Director,\nChairman,\n President,\nPartner", m$coefficients, m$coefficients+qnorm(0.025)*sqrt(diag(m$clustervcv)), m$coefficients+qnorm(0.975)*sqrt(diag(m$clustervcv)))
colnames(data1) <- c("job", "coef", "ci_lower", "ci_upper")
data.minister.post <- rbind(data1[which(rownames(data1)=="minister.post"),], data.minister.post)


m7d <- m <- felm(jobcat_prof ~ minister + minister.state + undersec + shadow.cabinet + frontbench.team + com.chair + com.member + minister.post + minister.state.post + undersec.post + shadow.cabinet.post + frontbench.team.post + com.chair.post + com.member.post + enter + leave | year + id | 0 | id, data=data)
summary(m7d)

data1 <- data.frame("Professional\nPosition", m$coefficients, m$coefficients+qnorm(0.025)*sqrt(diag(m$clustervcv)), m$coefficients+qnorm(0.975)*sqrt(diag(m$clustervcv)))
colnames(data1) <- c("job", "coef", "ci_lower", "ci_upper")
data.minister.post <- rbind(data1[which(rownames(data1)=="minister.post"),], data.minister.post)


data.minister.post <- data.minister.post[order(data.minister.post$coef),]


setEPS()
postscript("output/paper/fig5a.eps", width=5, height=5)
par(mar = c(3.5,7,1,1.2), mgp=c(2.5,1,0))
plot(data.minister.post$coef, c(1:length(data.minister.post$coef)), type="n", xlim=c(min(data.minister.post$ci_lower, na.rm=T), max(data.minister.post$ci_upper, na.rm=T)), ylim=c(1-0.2,length(data.minister.post$coef)+0.2), ylab="", xlab="Coefficients (Separate Regressions)", axes=F)
axis(1)
axis(2, at=c(1:length(data.minister.post$coef)), data.minister.post$job, cex.axis=1, las=2)

abline(v=0, col="grey", lwd=3)
abline(h=c(1:length(data.minister.post$coef)), col="lightgrey", lwd=0.7)

points(data.minister.post$coef, c(1:length(data.minister.post$coef)), pch=16, cex=1.75)
for(i in 1:length(data.minister.post$coef)){
	lines(c(data.minister.post$ci_lower[i], data.minister.post$ci_upper[i]), c(i,i), lwd=4)
}
dev.off()




### (b) Industries

data.minister.post <- NULL

m8a <- m <- felm(indcat_health ~ minister + minister.state + undersec + shadow.cabinet + frontbench.team + com.chair + com.member + minister.post + minister.state.post + undersec.post + shadow.cabinet.post + frontbench.team.post + com.chair.post + com.member.post + enter + leave | year + id | 0 | id, data=data)
summary(m8a)

data1 <- data.frame("Health", m$coefficients, m$coefficients+qnorm(0.025)*sqrt(diag(m$clustervcv)), m$coefficients+qnorm(0.975)*sqrt(diag(m$clustervcv)))
colnames(data1) <- c("job", "coef", "ci_lower", "ci_upper")
data.minister.post <- rbind(data1[which(rownames(data1)=="minister.post"),], data.minister.post)


m8b <- m <- felm(indcat_finance ~ minister + minister.state + undersec + shadow.cabinet + frontbench.team + com.chair + com.member + minister.post + minister.state.post + undersec.post + shadow.cabinet.post + frontbench.team.post + com.chair.post + com.member.post + enter + leave | year + id | 0 | id, data=data)
summary(m8b)

data1 <- data.frame("Finance", m$coefficients, m$coefficients+qnorm(0.025)*sqrt(diag(m$clustervcv)), m$coefficients+qnorm(0.975)*sqrt(diag(m$clustervcv)))
colnames(data1) <- c("job", "coef", "ci_lower", "ci_upper")
data.minister.post <- rbind(data1[which(rownames(data1)=="minister.post"),], data.minister.post)


m8c <- m <- felm(indcat_consulting ~ minister + minister.state + undersec + shadow.cabinet + frontbench.team + com.chair + com.member + minister.post + minister.state.post + undersec.post + shadow.cabinet.post + frontbench.team.post + com.chair.post + com.member.post + enter + leave | year + id | 0 | id, data=data)
summary(m8c)

data1 <- data.frame("Consulting", m$coefficients, m$coefficients+qnorm(0.025)*sqrt(diag(m$clustervcv)), m$coefficients+qnorm(0.975)*sqrt(diag(m$clustervcv)))
colnames(data1) <- c("job", "coef", "ci_lower", "ci_upper")
data.minister.post <- rbind(data1[which(rownames(data1)=="minister.post"),], data.minister.post)


m8d <- m <- felm(indcat_knowledge ~ minister + minister.state + undersec + shadow.cabinet + frontbench.team + com.chair + com.member + minister.post + minister.state.post + undersec.post + shadow.cabinet.post + frontbench.team.post + com.chair.post + com.member.post + enter + leave | year + id | 0 | id, data=data)
summary(m8d)

data1 <- data.frame("Knowledge", m$coefficients, m$coefficients+qnorm(0.025)*sqrt(diag(m$clustervcv)), m$coefficients+qnorm(0.975)*sqrt(diag(m$clustervcv)))
colnames(data1) <- c("job", "coef", "ci_lower", "ci_upper")
data.minister.post <- rbind(data1[which(rownames(data1)=="minister.post"),], data.minister.post)


m8e <- m <- felm(indcat_goods ~ minister + minister.state + undersec + shadow.cabinet + frontbench.team + com.chair + com.member + minister.post + minister.state.post + undersec.post + shadow.cabinet.post + frontbench.team.post + com.chair.post + com.member.post + enter + leave | year + id | 0 | id, data=data)
summary(m8e)

data1 <- data.frame("Goods", m$coefficients, m$coefficients+qnorm(0.025)*sqrt(diag(m$clustervcv)), m$coefficients+qnorm(0.975)*sqrt(diag(m$clustervcv)))
colnames(data1) <- c("job", "coef", "ci_lower", "ci_upper")
data.minister.post <- rbind(data1[which(rownames(data1)=="minister.post"),], data.minister.post)


m8f <- m <- felm(indcat_services ~ minister + minister.state + undersec + shadow.cabinet + frontbench.team + com.chair + com.member + minister.post + minister.state.post + undersec.post + shadow.cabinet.post + frontbench.team.post + com.chair.post + com.member.post + enter + leave | year + id | 0 | id, data=data)
summary(m8f)

data1 <- data.frame("Services", m$coefficients, m$coefficients+qnorm(0.025)*sqrt(diag(m$clustervcv)), m$coefficients+qnorm(0.975)*sqrt(diag(m$clustervcv)))
colnames(data1) <- c("job", "coef", "ci_lower", "ci_upper")
data.minister.post <- rbind(data1[which(rownames(data1)=="minister.post"),], data.minister.post)


m8g <- m <- felm(indcat_other ~ minister + minister.state + undersec + shadow.cabinet + frontbench.team + com.chair + com.member + minister.post + minister.state.post + undersec.post + shadow.cabinet.post + frontbench.team.post + com.chair.post + com.member.post + enter + leave | year + id | 0 | id, data=data)
summary(m8g)

data1 <- data.frame("Other", m$coefficients, m$coefficients+qnorm(0.025)*sqrt(diag(m$clustervcv)), m$coefficients+qnorm(0.975)*sqrt(diag(m$clustervcv)))
colnames(data1) <- c("job", "coef", "ci_lower", "ci_upper")
data.minister.post <- rbind(data1[which(rownames(data1)=="minister.post"),], data.minister.post)

data.minister.post <- data.minister.post[order(data.minister.post$coef),]


setEPS()
postscript("output/paper/fig5b.eps", width=5, height=5)
par(mar = c(3.5,6,1,1.2), mgp=c(2.5,1,0))
plot(data.minister.post$coef, c(1:length(data.minister.post$coef)), type="n", xlim=c(min(data.minister.post$ci_lower, na.rm=T), max(data.minister.post$ci_upper, na.rm=T)), ylim=c(1-0.2,length(data.minister.post$coef)+0.2), ylab="", xlab="Coefficients (Separate Regressions)", axes=F)
axis(1)
axis(2, at=c(1:length(data.minister.post$coef)), data.minister.post$job, cex.axis=1, las=2)

abline(v=0, col="grey", lwd=3)
abline(h=c(1:length(data.minister.post$coef)), col="lightgrey", lwd=0.7)

points(data.minister.post$coef, c(1:length(data.minister.post$coef)), pch=16, cex=1.75)
for(i in 1:length(data.minister.post$coef)){
	lines(c(data.minister.post$ci_lower[i], data.minister.post$ci_upper[i]), c(i,i), lwd=4)
}
dev.off()





##### FIGURE 6

m5 <- m <- felm(earnings.all.infl.log.1 ~ home + women.equalities + cabinetoffice + education.science.employment + work.pensions + health + justice + housing.comm.locgov + trade.industry.business.energy + sport.culture.media + environment.agriculture + regions + defense + transport + treasury + foreign + shadow.cabinet + frontbench.team + com.chair + com.member + home.post + women.equalities.post + cabinetoffice.post + education.science.employment.post + work.pensions.post + health.post + justice.post + housing.comm.locgov.post + trade.industry.business.energy.post + sport.culture.media.post + environment.agriculture.post + regions.post + defense.post + transport.post + treasury.post + foreign.post + shadow.cabinet.post + frontbench.team.post + com.chair.post + com.member.post + enter + leave | year + id | 0 | id, data=data)
summary(m5)

data1 <- data.frame(rownames(m$coefficients), m$coefficients, m$coefficients+qnorm(0.025)*sqrt(diag(m$clustervcv)), m$coefficients+qnorm(0.975)*sqrt(diag(m$clustervcv)))
colnames(data1) <- c("var", "coef", "ci_lower", "ci_upper")

data.post <- data1[21:36,]

data.post$name <- c("Home Office", "Women, Equalities", "Cabinet Office", "Education, Science,\n Employment", "Work, Pensions, Social Security", "Health", "Justice", "Housing, Communities,\n Local Government", "Trade, Industry, Business, Energy", "Culture, Media, Sports", "Environment, Agriculture", "Regions", "Defense", "Transport", "Treasury", "Foreign, Commonwealth,\n Int. Development, Europe")


data.post <- data.post[order(data.post$coef),]


setEPS()
postscript("output/paper/fig6.eps", width=6*1.62, height=6)
par(mar = c(4,11,1,1), mgp=c(3,1,0))
plot(data.post$coef, c(1:length(data.post$coef)), type="n", xlim=c(min(data.post$ci_lower, na.rm=T), max(data.post$ci_upper, na.rm=T)), ylim=c(1,length(data.post$coef)), ylab="", xlab="Coefficients", axes=F)
axis(1)
axis(2, at=c(1:length(data.post$coef)), data.post$name, cex.axis=0.75, las=2)

abline(v=0, col="grey", lwd=3)
abline(h=c(1:length(data.post$coef)), col="lightgrey", lwd=1)

points(data.post$coef, c(1:length(data.post$coef)), pch=16, cex=1.75)
for(i in 1:length(data.post$coef)){
	lines(c(data.post$ci_lower[i], data.post$ci_upper[i]), c(i,i), lwd=3)
}
dev.off()




# substnative impact of foreign, treasury, justice same meanbefore as above
ids <- unique(data$id[data$minister==1])
mindata <- data[data$id %in% ids,]
beforedata <- mindata[mindata$minister==0 & mindata$minister.post==0,]
meanbefore <- mean(beforedata$earnings.all.infl)


meanbefore
meanbefore*(exp(1)^(m5$coef[rownames(m5$coef)=="treasury.post"]))
meanbefore*(exp(1)^(m5$coef[rownames(m5$coef)=="foreign.post"]))
meanbefore*(exp(1)^(m5$coef[rownames(m5$coef)=="justice.post"]))


# test of joint significance for all  post-ministries
linearHypothesis(m5, c("home.post=0", "women.equalities.post=0", "cabinetoffice.post=0", "education.science.employment.post=0", "work.pensions.post=0", "health.post=0", "justice.post=0", "housing.comm.locgov.post=0", "trade.industry.business.energy.post=0", "sport.culture.media.post=0", "environment.agriculture.post=0", "regions.post=0", "defense.post=0", "transport.post=0", "treasury.post=0", "foreign.post=0"), test="F")







